﻿using System;
using System.Buffers;
using System.Linq;
namespace Xc.DataAccess.PcpChannels
{
    /// <summary>
    /// 执行升级应答包
    /// </summary>
    public class CloudExecuteUpdateRespond : RespondFrame
    {
        public CloudExecuteUpdateRespond(byte[] dataarea) : base(dataarea)
        {

        }

        protected override MessageCode? ValidateMessageCode => MessageCode.ExecuteUpdate;
        public ExecuteUpdate Status { get; set; }
        /// <summary>
        /// 新版本通知
        /// </summary>
        public enum ExecuteUpdate
        {
            /// <summary>
            /// 处理成功
            /// </summary>
            Success = 0x00,
            /// <summary>
            /// 设备使用中
            /// </summary>
            DeviceOnUse = 0x01,
            /// <summary>
            /// 电量不足
            /// </summary>
            VoltageLow = 0x04,
            /// <summary>
            /// 剩余空间不足
            /// </summary>
            SpaceInsufficient = 0x05,
            /// <summary>
            /// 内存不足
            /// </summary>
            OutOfMemory = 0x09,
        }
        public override string ToString()
        {
            return Status.ToString();
        }
        protected override bool SetDataArea(ref SequenceReader<byte> dataArea)
        {
            if (dataArea.TryRead(out var c))
            {
                Status = (ExecuteUpdate)c;
                return true;
            }
            return false;
        }
    }
}
